package com.mzd.multipledatasources4.controller;

import com.mzd.multipledatasources4.bean.TeachersBean;
import com.mzd.multipledatasources4.bean.TestBean;
import com.mzd.multipledatasources4.service.TransactionService1;
import com.mzd.multipledatasources4.service.TransactionService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * 多数据源事务测试
 * @author Administrator
 */
@RestController
public class TransactionController {

    @Autowired
    private TransactionService1 ts1;
    @Autowired
    private TransactionService2 ts2;

    @RequestMapping("/savetest.do")
    public String saveTest() {
        TestBean tb = new TestBean();
        tb.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        tb.setScore(70);
        tb.setClassId("1");
        tb.setUserId("a");
        ts1.test01SaveTestBean(tb);
        return "success";
    }

    @RequestMapping("/saveteacher.do")
    public String saveTeacher() {
        TeachersBean tb = new TeachersBean();
        tb.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        tb.setTeacherName("王老师");
        tb.setClassId("1");
        ts2.test02SaveTeachersBean(tb);
        return "success";
    }


}
